package com.adoalonso.gwtbingmaps.client.example;

import com.adoalonso.gwtbingmaps.client.BingMap;
import com.google.gwt.dom.client.Style;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.AbsolutePanel;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;

/**
 * Example class containing the Bing Maps for GWT demo.
 * 
 * @author adoalonso
 */
public class Example extends Composite {

  private final FlowPanel basePanel;
  private final AbsolutePanel mapContainer;
  private final FlowPanel controlsContainer;
  private final String mapId = "mapId";

  public Example() {
    basePanel = new FlowPanel();
    initWidget(basePanel);

    mapContainer = new AbsolutePanel();
    mapContainer.setSize("600px", "600px");
    mapContainer.getElement().getStyle().setFloat(Style.Float.LEFT);
    mapContainer.getElement().getStyle().setZIndex(0);// mandatory for the bing
                                                      // map container
    mapContainer.getElement().setId(mapId);
    DOM.setStyleAttribute(mapContainer.getElement(), "border",
        "1px solid black");

    controlsContainer = new FlowPanel();
    controlsContainer.setWidth("300px");
    controlsContainer.getElement().getStyle().setFloat(Style.Float.LEFT);

    basePanel.add(mapContainer);
    basePanel.add(controlsContainer);

    controlsContainer.add(new HTML("here goes the controls"));
  }

  @Override
  protected void onAttach() {
    super.onAttach();
    // BingMap map = BingMap.buildMe("mapId");
    // map.loadMap();
    if (BingMap.isBingMapsLibraryLoaded()) {
      BingMap mapa = (BingMap) BingMap.buildMe(mapId);
      mapa.loadMap();
      Window.alert("cargado mapa");
    }

  }
}
